//
//  GuideViewController.m
//  card
//
//  Created by 韦显光 on 2017/11/13.
//  Copyright © 2017年 xg韦. All rights reserved.
//

#import "GuideViewController.h"
#import "tabbarViewController.h"
@interface GuideViewController ()<UIScrollViewDelegate>
{
    UIScrollView *splashScrollView;
}
- (IBAction)open:(UIButton *)sender;

@end

@implementation GuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self BootAnimation];


    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/* 启动动画 */
- (void)BootAnimation
{
    NSArray *activityBannersArr = @[@"ydk1",@"ydk2",@"ydk3"];
    splashScrollView = [[UIScrollView alloc] init];
    splashScrollView.frame = CGRectMake(0, 0, DEVW, DEVH);
    splashScrollView.delegate = self;
    splashScrollView.bounces = NO;
    splashScrollView.scrollEnabled = YES;
    splashScrollView.contentOffset = CGPointMake(0, 0);
    splashScrollView.contentSize = CGSizeMake(activityBannersArr.count * DEVW, 0);
    splashScrollView.pagingEnabled = YES;
    splashScrollView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:splashScrollView];
    [self.view bringSubviewToFront:splashScrollView];
    UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapHandler:)];
    [splashScrollView addGestureRecognizer:recognizer];
    
    for (int i = 0; i < activityBannersArr.count; i++){
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(splashScrollView.frame.size.width * i, 0, splashScrollView.frame.size.width, splashScrollView.frame.size.height)];
        UIImage *image = [UIImage imageNamed:[activityBannersArr objectAtIndex:i]];
        imageView.image = image;
        [splashScrollView addSubview:imageView];
    }
}


- (void)tapHandler:(UITapGestureRecognizer *)sender
{
    if (splashScrollView.contentOffset.x / DEVW == 2){
        [splashScrollView removeFromSuperview];
        [self open:nil];
        
    }
}

- (IBAction)open:(UIButton *)sender {
    UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"login" bundle:nil];
    UIViewController*secondViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"Login"];
   AppDelegate *newDelegate = [[UIApplication sharedApplication] delegate];
    newDelegate.window.rootViewController=secondViewController;
    [newDelegate.window makeKeyAndVisible];
}
@end
